package com.ylr.base.common.enums;

import com.ylr.base.common.dto.NameValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2023-04-18 22:14:44
 * className: ModuleEnum 系统模块枚举类
 * version: 1.0
 * description:
 */
@Getter
@AllArgsConstructor
public enum ModuleEnum {

    GATEWAY(0, "gateway", "网关模块"),
    BASIC(1, "basic", "基础模块"),
    ADMIN(2, "admin", "后台模块"),
    BLOG(3, "blog", "博客模块"),
    CONFIG(4, "config", "配置模块"),
    FILE(5, "file", "文件模块"),
    GAME(6, "game", "游戏模块"),
    INDEX(7, "index", "首页模块"),
    PRODUCE(8, "produce", "生成模块"),
    SEND(9, "send", "发送模块"),
    ;

    /**
     * 模块值
     */
    private final Integer value;
    /**
     * 模块code
     */
    private final String code;
    /**
     * 模块名称
     */
    private final String name;

    /**
     * 根据模块code获取模块枚举对象
     * @param code 模块code
     * @return 模块枚举对象
     */
    public static ModuleEnum getModuleEnum(String code) {
        for (ModuleEnum moduleEnum : values()) {
            if (moduleEnum.code.equals(code)) {
                return moduleEnum;
            }
        }
        return null;
    }

    /**
     * 根据模块value获取模块枚举对象
     * @param value 模块value
     * @return 模块枚举对象
     */
    public static ModuleEnum getModuleEnum(Integer value) {
        for (ModuleEnum moduleEnum : values()) {
            if (moduleEnum.value.equals(value)) {
                return moduleEnum;
            }
        }
        return null;
    }

    /**
     * 获取模块枚举列表
     */
    public static List<NameValue<Integer>> getModuleEnumList(Integer filterValue) {
        return Stream.of(values())
                .filter(moduleEnum -> !moduleEnum.value.equals(filterValue))
                .map(moduleEnum -> new NameValue<>(moduleEnum.name, moduleEnum.value))
                .collect(Collectors.toList());
    }
}
